package com.zhongmeng.rxjava2test.modle


import com.zhongmeng.rxjava2test.base.BaseModle
import com.zhongmeng.rxjava2test.utils.DisposableUtils

import io.reactivex.disposables.Disposable
import io.reactivex.Observable

/**
 * author :rcw.
 * date :2017/10/11 11:04.
 * loginModle的实现类
 */

class LoginModleImpl(private val onRequestListener: BaseModle.OnRequestListener<*>//监听回调
) : BaseModle {


    /*@Override
    public Disposable login(String username, String password) {
        Observable<LoginBean> observable= ApiServiceManager.getCallBackData("db9fe289c32eeda773db291f29d9d461",username,password);
        Disposable disposable=observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<LoginBean>() {
                    @Override
                    public void accept(LoginBean loginBean) throws Exception {
                        if (onLoginListener!=null){
                            onLoginListener.loginSuccess(loginBean);
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        if (onLoginListener!=null){
                            onLoginListener.loginFail(throwable);
                        }
                    }
                });

        return disposable;
    }*/

    override fun <T> getObservable(observable: Observable<T>, which: Int): Disposable {
        return DisposableUtils.getDisposable<T>(observable, which, onRequestListener as BaseModle.OnRequestListener<T>)
    }
}
